<template>
    <header>
          <ul>
            <!-- <li>2018-11-16   星期五</li> -->
            <!-- <li><icon name="header_msg"></icon>99+</li> -->
            <!-- <li @click.stop = "routerToAdminWelcome"  style="cursor:pointer;">我的工作台</li> -->
            <li>工号 : {{getStaffNum}}</li>
            <li>姓名 : {{getUserName}}</li>
            <li @click.stop="logout">退出</li>
          </ul>
        </header>
</template>

<script>
import http from "@/assets/js/http"
import _g from "@/assets/js/global"
import config from "@/assets/js/config.js"
import { mapGetters } from 'vuex'

import Cookies from "js-cookie"

export default {
    data(){
        return{
            staffNum : '',  //..工号
            userName : '',  //..姓名
        }
    },
    created() {
        // alert(this.$store.getters.userName)
        // this.getUserStaffNumAndName()
    },

    mounted() {
    },
    computed: {
        ...mapGetters([                                                                         //  用户权限
                'roles','getUserName','getStaffNum','getFinishedReMsg','getIsAdmin'
        ])
    },
     mixins: [http],
    methods: {
        /* 跳转到管理员页面 */
        // routerToAdminWelcome(){
        //     this.$store.dispatch('setIsAdmin',true)
        //     this.$router.push('/admin/welcome')
        // },

        /* 退出登录 */
        logout(){
            console.log(Cookies.get())
            const that = this
            let str = '是否退出?'

            if(!that.getFinishedReMsg){                                                 //  如果有履历基本信息没有填写
                str = '尚有为未填写完成的信息，确定退出?'
            }

            that.$confirm(str, '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning',
                  center: true
              }).then(() => {
                    _g.showLoading('退出中')
                    that.apiPost('admin/base/logout').then((res) => {
                        _g.showLoading().close()
                        if(typeof res === 'string'){
                            res = JSON.parse(res)
                        }
                        if (res.code != 200) {
                            that.handleError(res)
                        } else {
                            if(res.data.isSuccess === 0){
                                _g.toastMsg("success", res.message)

                                that.$store.dispatch('setPhotoPath','')
                                // 清除cookie与storage
                                Object.keys(Cookies.get()).forEach((key) => {
                                    Cookies.remove(key)
                                })


                                that.$router.push('/')
                            }
                        }
                    })
              }).catch(() => {})
        }
    }
}
</script>

<style scoped>
/* 头部组件 */
header{
  background-color:#e3e4e5;
  padding-left:20px;
  padding-right:20px;
  height:30px;
  line-height:30px;
  font-size:12px;
}
header ul{
  float:right;
}
header > ul > li{
  display:inline-block;
  color:#999;
  text-align:center;
}
header > ul > li:not(:first-child):hover{
    color:#eb6100;
    cursor: pointer;
}
header > ul > li:not(:last-child)::after{
  width:1px;
	height:9px;
	content:'';
	display: inline-block;
  clear: both;
  background-color:#ccc;
  margin-left:9px;
  margin-right:9px;
}

</style>

